<template>
  <div>
<van-datetime-picker
  v-model="currentDate"
  type="date"
  title="选择年月日"
  :min-date="minDate"
  :max-date="maxDate"
  @cancel="$emit('close')"
  @confirm="onConfirm"
/>
  </div>
</template>

<script>
import { updateUserProfile } from '@/api/user'
import dayjs from 'dayjs'
export default {
  name: 'UpdateBirthday',
  props: {
    value: {
      type: String,
      required: true
    }
  },
  components: {},
  data () {
    return {
      minDate: new Date(1970, 0, 1),
      maxDate: new Date(),
      currentDate: new Date(this.value)
    }
  },
  created () {

  },
  methods: {
    async onConfirm () {
      this.$toast.loading({
        message: '保存中',
        duration: 0,
        forbidClick: true
      })
      const birthday = dayjs(this.currentDate).format('YYYY-MM-DD')
      await updateUserProfile({
        birthday: birthday
      })
      this.$toast.success({
        message: '更新成功'
      })
      this.$emit('input', birthday)
      this.$emit('close')
    }
  }
}
</script>

<style lang="less" scoped>

</style>
